<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class UserDownloadLog extends Model
{
    protected $fillable = ['user_id', 'resource_id'];

    public static function hadDownloadedInWeek($user_id, $resource_id)
    {
        $log = UserDownloadLog::query()
            ->where('user_id', $user_id)
            ->where('resource_id', $resource_id)
            ->where('created_at', '>=', Carbon::now()->subWeek())
            ->first();

        return $log;
    }
}
